#!/bin/sh
# This regression test is a part of SIPp.
# With -t ui, two names of an address in the -ip_field (127.0.0.1 and
# 127.1) share the socket bound to it: the UAS binds it once at startup,
# and the UAC's call on the second name takes the main socket rather
# than binding the address and port again.
. "`dirname "$0"`/../functions"; init

printf 'SEQUENTIAL\n127.0.0.1;\n127.1;\n' >ips.csv
sippbg -sn uas -t ui -inf ips.csv -ip_field 0 -i 127.0.0.1 -p 5070 -m 2 \
    -timeout 10 -timeout_error
uas=$pid
sippfg -sn uac -t ui -inf ips.csv -ip_field 0 -m 2 -r 10 -i 127.0.0.1 \
    -p 5071 127.0.0.1:5070 -timeout 8 -timeout_error >/dev/null 2>&1
status=$?
wait $uas
uas_status=$?
rm -f ips.csv

if test $status -ne 0; then
    fail "UAC failed with $status"
elif test $uas_status -ne 0; then
    fail "UAS failed with $uas_status"
else
    ok
fi
